<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/7/1 0001
 * Time: 上午 11:05
 */

namespace app\sports_admin\service;

use app\exception\AppExplainException;
use app\sports_admin\model\AppExplain as AppExplainModel;
class AppExplain extends Base
{
    /**
     * 首页内容
     */
    public static function index()
    {
        $params = self::getHttpRequestPrograms()->param();
        $params['page'] = intval($params['page']);
        $params['rows'] = intval($params['rows']);
        $info = AppExplainModel::getList($params);
        return json($info);
    }

    /**
     * 添加使用说明
     */
    public static function insert()
    {
        $params = self::getHttpRequestPrograms()->param();
        $bool = AppExplainModel::create(['title'=>$params['title'],'content'=>htmlspecialchars($params['content'])]);
        if(!$bool){
            throw new AppExplainException(['msg'=>'添加失败','errorCode'=>400]);
        }
        return json(['msg'=>'添加成功','code'=>200]);
    }
    /**
     * 删除使用说明
     */
    public static function delete()
    {
        $params = self::getHttpRequestPrograms()->param();
        $bool = AppExplainModel::destroy($params['id']);
        if(!$bool){
            throw new AppExplainException(['msg'=>'删除失败','errorCode'=>400]);
        }
        return json(['msg'=>'删除成功','code'=>200]);
    }
}